/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-08-05
 * Time: 20:58
 */
class Solution1 {
    public void swap(int[] nums,int i,int j) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }
    public void sortColors(int[] nums) {
        int n = nums.length;
        int left = -1, right = n,i = 0;
        while(i < right) {
            if(nums[i] == 0) {
                // swap(nums[++left],nums[i++]);
                swap(nums,++left,i++);
            }else if(nums[i] == 1){
                i++;
            }else {
                swap(nums,--right,i);
            }
        }
    }
}
